<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const str = "12:30:40,20:40:20";

      const reg = /(?<h>\d{2}):(?<m>\d{2}):(?<s>\d{2})/g;
      console.log(str.replace(reg, "$<h>时$<m>分$<s>秒"));
    </script>
  </body>
</html>
